package com.wanxi.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MyStreamObject {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("zhangsan", 23));
        list.add(new Student("lisi", 24));
        list.add(new Student("wangwu", 25));
        Stream<Student> studentStream = list.stream().filter(student -> student.getAge() >= 24);
//        System.out.println(studentStream.collect(Collectors.toList()));
//        System.out.println(studentStream.collect(Collectors.toSet()));
//        Map<Object, Object> collect = studentStream.collect(Collectors.toMap(new Function<Object, Object>() {
//            @Override
//            public Object apply(Object o) {
////                System.out.println(o + "------");
//                Student student = (Student) o;
//                return student.getName();
//            }
//        }, new Function<Student, Object>() {
//            @Override
//            public Object apply(Student student) {
////                System.out.println(student);
//                return student.getAge();
//            }
//        }));
        Map<Object, Object> collect = studentStream.collect(Collectors.toMap(Student::getName, Student::getAge));
        Set<Object> objects = collect.keySet();
        for (Object o : objects
        ) {
            System.out.println(o + "-----" + collect.get(o));
//            System.out.println(collect.get(o));
        }

    }
}
